/* Copyright (c) 2004-2024 Peigen.info. All rights reserved. */

package info.peigen.hotpot.component.sms.service.processor;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONWriter;
import info.peigen.hotpot.common.service.base.processor.Processor;
import info.peigen.hotpot.common.service.base.processor.ProcessorServiceContext;
import info.peigen.hotpot.component.sms.config.SmsProperties;
import info.peigen.hotpot.component.sms.service.order.SingleSmsOrder;
import lombok.extern.slf4j.Slf4j;
import org.dromara.sms4j.api.SmsBlend;
import org.dromara.sms4j.api.entity.SmsResponse;
import org.dromara.sms4j.core.factory.SmsFactory;
import org.noear.solon.annotation.Component;
import org.noear.solon.annotation.Inject;

/**
 * <b>(SendSingleSmsProcessor)</b>
 *
 * @author Peigen
 * @version 1.0.0
 * @since 2022/5/26
 */
@SuppressWarnings({"rawtypes"})
@Slf4j
@Component
public class SendSingleSmsProcessor extends AbstractSmsServiceProcessor implements Processor {
    @Inject
    private SmsProperties smsProperties;

    @SuppressWarnings("RedundantMethodOverride")
    @Override
    public Integer level() {
        return 50;
    }

    @Override
    public void execute(ProcessorServiceContext serviceContext) {
        SingleSmsOrder order = (SingleSmsOrder) serviceContext.getOrder();
        if (smsProperties.isEnable()) {
            SmsBlend    smsBlend    = SmsFactory.getSmsBlend();
            SmsResponse smsResponse = smsBlend.sendMessage(order.getMobile(), order.getTemplateId(), order.getParams());
            log.info(JSON.toJSONString(smsResponse, JSONWriter.Feature.PrettyFormat));
        }
    }
}